import { read,utils } from 'xlsx/xlsx.mjs'
export default async function (file,sheetName,callback) {
  const fileReader = new FileReader()
  fileReader.onload = ev =>{
    const resdata = {}
    let workbook
    try {
      workbook = read(ev.target.result, {
        type: 'binary'
      })
    } catch (e) {
      console.error(e)
      return
    }
    const {SheetNames,Sheets} = workbook
    for (const sheet in Sheets){
      if(sheetName != sheet) continue
      if (Sheets.hasOwnProperty(sheet)){
        const fromTo = Sheets[sheet]['!ref'] //位置
        if(fromTo){
          const data = utils.sheet_to_json(Sheets[sheet])
          resdata[sheet] = { data }
        }
      }
    }
    callback(resdata)
  }
  await fileReader.readAsArrayBuffer(file)
  return false
}